﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Maknys.Consultator.Services;
using Maknys.Consultator.ServiceContracts;
using Maknys.Consultator.DomainModel;

namespace mainWindow
{
    public partial class Main : Form
    {
        private readonly ITreeService treeService;
        private  DataBase dataBaseWindow;
        private List<string> list = new List<string>();

        public Main()
        {
            InitializeComponent();
            treeService = new TreeService();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            main();
        }

        public void fillcomboBox()
        {
            listBox1.Items.Clear();
            string SearchItem = "Questions";
            list.Clear();
            list = treeService.GetElementList(SearchItem);
            foreach (string node in list)
            {
                comboBox1.AutoCompleteCustomSource.Add(node);
            }
        }

        private void main()
        {
            treeService.MakeTree();
            treeService.FillTree();
            fillcomboBox();
        }

        private void duomenųBazėToolStripMenuItem_Click(object sender, EventArgs e)
        {
            dataBaseWindow = new DataBase();
            dataBaseWindow.Show();
        }

        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
             string sentence = (string)listBox1.SelectedItem;
             list.Clear();
             listBox1.Items.Clear();
             list = treeService.GetElementList(sentence);
             foreach (string node in list) 
             {
                 listBox1.Items.Add(node);
             }
        }

        private void uždarytiToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void apieToolStripMenuItem_Click(object sender, EventArgs e)
        {
            MessageBox.Show("Author: Ernestas Maknys IF-1/8", "About");
        }

        private void comboBox1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                string SearchItem = (string)comboBox1.SelectedText;
                list.Clear();
                list = treeService.GetElementList(SearchItem);
                foreach (string node in list)
                {
                    listBox1.Items.Add(node);
                }
            }
        }

    }
}
